﻿using DisplayDemoApp.Commons;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.ObjectModel;
using System.Runtime;
using System.Windows.Input;

namespace DisplayDemoApp.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        #region 属性
        private string _title = "山河大学人数班级表";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
        private int totolStudents;

        public int TotolStudents
        {
            get { return totolStudents; }
            set { totolStudents = value; RaisePropertyChanged(); }
        }
        private int totolClasses;

        public int TotolClasses
        {
            get { return totolClasses; }
            set { totolClasses = value; RaisePropertyChanged(); }
        }

        private ObservableCollection<ClassModel> schoolItemsSource;

        public ObservableCollection<ClassModel> SchoolItemsSource
        {
            get { return schoolItemsSource; }
            set { schoolItemsSource = value; RaisePropertyChanged(); }
        }

        public DelegateCommand<object> AddCommand { get; set; }
        #endregion


        public MainWindowViewModel()
        {
            SchoolItemsSource = new ObservableCollection<ClassModel>();
            AddCommand = new DelegateCommand<object>(OnAddStu);
            UpdateClassItem();
        }

        private void OnAddStu(object obj)
        {
            
        }

        private void UpdateClassItem()
        {
            //添加30个班级测试数据
            SchoolItemsSource.Clear();

            for (int i = 1; i <= 30; i++)
            {
                var students = new ObservableCollection<StudentModel>();
                for (int n = 1; n <= 10 + i; n++)
                {
                    students.Add(new StudentModel() { 
                        No = n,
                        StuName = "李某" + n,
                        StuSex = (n % 2 == 0) ? "男" : "女",
                        StuContact = string.Format("137888866{0:D2}", n),
                        StuAddress = string.Format("中国山河省有为市{0}区10086号", n),
                        StuGrades = new Random().Next(80, 100),
                        EditStuCommand = null,
                        DelStuCommand = null,
                    });;
                }
                SchoolItemsSource.Add(new ClassModel
                {
                    Id = i,
                    ClassName = string.Format("山河{0}班", i),
                    ClassStudents = students.Count,
                    ClassStyle = (i % 2 == 0) ? "普通班级" : "艺术班级",
                    AddCommand = AddCommand,
                    EditCommand = null,
                    DelCommand = null,
                    StudentsItemsSource = students,
                });
                //在校总人数
                TotolStudents += students.Count;
            }

            //班级数
            TotolClasses = SchoolItemsSource.Count;
        }
    }
}
